package main

import (
	"log"
	"mq_demo/internal"
)

func main() {
	// 设置实例的接入点。
	// 设置实例的接入点。
	hostName := "rabbitmq-cn-aic48045w02.cn-hangzhou.amqp-28.net.mq.amqp.aliyuncs.com"
	// 设置实例的静态用户名密码。
	userName := "MjpyYWJiaXRtcS1jbi1haWM0ODA0NXcwMjpMVEFJNXQ3aHdKSjQyTmJQOWJMS0NadVo="
	passWord := "NDRCRjcwREQxODI0MTI2MDI0RjgxNDcxNzg5NzlBQjU5MzU0OEM4QjoxNzQ0ODE0MzY5OTI5"

	// 设置实例的Vhost。
	virtualHost := "test-vhost"
	rabbitmq, err := internal.NewRabbitMQ(&internal.RabbitMQConfig{
		HostName: hostName,
		Username: userName,
		Password: passWord,
		Vhost:    virtualHost,
	})
	if err != nil {
		log.Fatal(err)
	}
	defer rabbitmq.Close()

	// 声明Queue
	queueName := "test-queue"
	err = rabbitmq.QueueDeclare(queueName)
	if err != nil {
		log.Fatal(err)
	}

	// 开始消费消息
	ch, err := rabbitmq.Consume("test-consumerTag")
	if err != nil {
		log.Fatal(err)
	}
	for d := range ch {
		log.Printf("Received a message: %s, deliveryTag: %d, messageId: %s", d.Body, d.DeliveryTag, d.MessageId)
		d.Ack(false)
	}
}
